import http from '@/utils/http/axios';
export interface BasicResponseModel<T = any> {
  code: number;
  message: string;
  result: T;
}

export interface BasicPageParams {
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: '/sys/user/userInfo',
    method: 'get',
  });
}

/**
 * @description: 用户登录
 */
export function login(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/login',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登出
 */
export function logout() {
  return http.request({
    url: '/logout',
    method: 'POST',
  });
}

/**
 * 查询用户列表
 * @param params
 */
export function userList(params) {
  return http.request({
    url: '/sys/user',
    method: 'get',
    params,
  });
}

/**
 * 禁用用户
 * @param id
 */
export function disabledUser(id) {
  return http.request({
    url: `/sys/user/disabledUser/${id}`,
    method: 'post',
  });
}
export function enableUser(id) {
  return http.request({
    url: `/sys/user/enabledUser/${id}`,
    method: 'post',
  });
}
export function deleteUser(ids) {
  return http.request({
    url: '/sys/user',
    method: 'delete',
    params: { ids: ids },
  });
}
export function saveUser(data) {
  return http.request({
    url: '/sys/user',
    method: 'post',
    data,
  });
}
export function updateUser(data) {
  return http.request({
    url: '/sys/user',
    method: 'put',
    data,
  });
}
export function editUser(data) {
  return http.request({
    url: '/sys/user/editUser',
    method: 'put',
    data,
  });
}
/**
 * 校验用户名
 * @param params
 */
export function checkUsername(params) {
  return http.request({
    url: '/sys/user/checkUsername',
    method: 'get',
    params,
  });
}
export function checkMobile(params) {
  return http.request({
    url: '/sys/user/checkMobile',
    method: 'get',
    params,
  });
}
export function checkUniqueness(params) {
  return http.request({
    url: '/sys/user/checkUniqueness',
    method: 'get',
    params,
  });
}
export function sendSmsCode(mobile) {
  return http.request({
    url: `/sms/sendSms/${mobile}`,
    method: 'get',
  });
}

/**
 * 通过手机号码找回密码
 * @param params
 */
export function findPassByMobile(params) {
  return http.request({
    url: `/sys/user/findPassByMobile`,
    method: 'post',
    params,
  });
}

/**
 * 通过邮件地址找回密码
 * @param params
 */
export function findPassByEmail(params) {
  return http.request({
    url: `/sys/user/findPassByEmail`,
    method: 'post',
    params,
  });
}

/**
 * 发送邮件
 * @param email
 */
export function sendEmailCode(email) {
  return http.request({
    url: `/email/sendResetCode/${email}`,
    method: 'get',
  });
}
export function sendEditEmailCode(email) {
  return http.request({
    url: `/email/sendEditEmailCode/${email}`,
    method: 'get',
  });
}
export function smsCodeLogin(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/mobile/login',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}
export function register(data) {
  return http.request({
    url: `/sys/user/register/${data.smsCode}`,
    method: 'post',
    data,
  });
}
export function updatePassword(params) {
  return http.request({
    url: '/sys/user/updatePassword',
    method: 'post',
    params,
  });
}

/**
 * 校验密码是否一致
 * @param params
 */
export function checkPassword(params) {
  return http.request({
    url: '/sys/user/checkPasswd',
    method: 'post',
    params,
  });
}

/**
 * 修改手机号码
 * @param params
 */
export function editMobile(params) {
  return http.request({
    url: '/sys/user/editMobile',
    method: 'post',
    params,
  });
}

/**
 * 修改邮箱
 * @param params
 */
export function editEmail(params) {
  return http.request({
    url: '/sys/user/editEmail',
    method: 'post',
    params,
  });
}
